package com.CTAtracker.android.Adapters;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.CTAtracker.android.R;

/**
 * This class is a adapter for the sliding menu. 
 */
public class SlidingMenuItemAdapter extends ArrayAdapter<Pair<String, Integer>> {
	
	/**
	 * The layout to inflate
	 */
	private LayoutInflater _layoutInflater = null;
	/**
	 * The resource Id
	 */
	private int _resourceId = 0;
	/**
	 * The List to adapt 
	 */
	private ArrayList<Pair<String, Integer>> _listMenu;

	/**
	 * Constructor of the class. Instance the attribute and call the super method.
	 * @param context The context of the application
	 * @param resourceId The id of the resource to inflate 
	 * @param objects the list of function to adapt to the view
	 */
	public SlidingMenuItemAdapter(Context context, int resourceId, List<Pair<String, Integer>> objects) {
		super(context, resourceId, 0, objects);

		_layoutInflater = LayoutInflater.from(context);
		_resourceId = resourceId;
		_listMenu = (ArrayList<Pair<String, Integer>>) objects;
	}

	/**
	 * This method is call every time we want to display the view
	 * Display the list of the different functions
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		final Pair<String, Integer> row = _listMenu.get(position);
		convertView = _layoutInflater.inflate(_resourceId, parent, false);

		final TextView textView = (TextView) convertView.findViewById(R.id.textView);
		textView.setText(row.first);

		final ImageView imageView = (ImageView) convertView.findViewById(R.id.imageView);
		imageView.setImageResource(row.second);

		return convertView;
	}
}
